package hos.okgo.converter;

import java.io.IOException;
import java.lang.reflect.Type;

import hos.okhttp.utils.OkHttpResponseUtils;
import okhttp3.Response;

/**
 * <p>Title: JsonConvert </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023-02-16 22:51
 */
public abstract class OkGoResponseJsonDataConverter<T> extends OkGoResponseJsonConverter<T> {

    String data = "data";

    public OkGoResponseJsonDataConverter() {
        this("data");
    }

    public OkGoResponseJsonDataConverter(String data) {
        super();
        this.data = data;
    }

    public OkGoResponseJsonDataConverter(String success, String code, String message) {
        super(success, code, message);
    }

    public OkGoResponseJsonDataConverter(String success, String code) {
        super(success, code);
    }

    public OkGoResponseJsonDataConverter(String success, String code, String data, String message) {
        super(success, code, message);
        this.data = data;
    }

    public OkGoResponseJsonDataConverter(Type type, String success, String code, String message, String data) {
        super(type, success, code, message);
        this.data = data;
    }

    public OkGoResponseJsonDataConverter(Type type, String success, String code, String data) {
        super(type, success, code);
        this.data = data;
    }

    public OkGoResponseJsonDataConverter(Type type, String data) {
        super(type);
        this.data = data;
    }

    public OkGoResponseJsonDataConverter(Type type) {
        this(type, "data");
    }

    @Override
    public T parseJson(Type succeed, Response response) throws IOException {
        String json = OkHttpResponseUtils.requireJsonData(response, code, message, success, data);
        return parseBody(succeed, response, json);
    }
}
